import { ModalPropsType } from "@/components/GlobalModal";
import { UserInfoType } from "@/store/user";

class MonitorCode {
    modalProps: ModalPropsType;
    constructor() {
        this.modalProps = {
            title: "",
            content: "",
            cancelText: "取消",
            confirmText: "确定",
            onCancel: () => { },
            onConfirm: () => { },
            hideModal: () => { }
        }
    }
    encounter(userInfo: UserInfoType, hideModal: () => void, gotoWord: () => void):ModalPropsType {
        return handleCode0(this.modalProps, userInfo, hideModal, gotoWord)
    }
    encounter1000(hideModal: () => void , againCreate: () => void):ModalPropsType {
        return handleCode1000(this.modalProps , hideModal , againCreate );
    }
    encounter1001(hideModal: () => void ):ModalPropsType {
        return handelCode1001(this.modalProps,hideModal)
    }
}

/**
 * 正常制作的情况 code为0
 * @param modalProps 
 * @param userInfo 
 * @param hideModal 
 * @param gotoWord 
 * @returns 
 */
const handleCode0 = (
        modalProps: ModalPropsType, 
        userInfo: UserInfoType, 
        hideModal: () => void,
        gotoWord: () => void
    ) => {
    const { is_pro, points: { charge_points, free_points, free_times } } = userInfo
    const totalPoints = charge_points + free_points;

    if (!is_pro) {
        if (free_times === 0 && totalPoints >= 0) {
            modalProps = {
                title: "正在制作中",
                content: "使用点数制作中，请在作品页面查看制作结果~",
                confirmText: "查看作品",
                cancelText: "留在当前",
                onConfirm: gotoWord,
                onCancel: hideModal,
                hideModal,
            }
        } else {
            modalProps = {
                title: "正在制作中",
                content: "免费制作中，请在作品页面查看制作结果~",
                confirmText: "查看作品",
                cancelText: "留在当前",
                onConfirm: gotoWord,
                onCancel: hideModal,
                hideModal,
            }
        }
    }
    return modalProps;
};


/**
 * 是否再次制作的情况 code 为1000
 * @param modalProps 
 * @param hideModal 
 * @param againCreate 
 * @returns  ModalPropsType
 */
const handleCode1000 =  (
    modalProps: ModalPropsType,
    hideModal: () => void,
    againCreate:() => void,
) => {
    modalProps = {
        title: "再次制作",
        content: "当前图片和模板已经制作过，是否再次制作",
        confirmText: "再次制作",
        cancelText: "取消",
        onConfirm: againCreate,
        onCancel: hideModal,
        hideModal,
    }
    return modalProps
};

/**
 * 点数不足的情况 code 为1001
 * @param modalProps 
 * @param hideModal 
 * @returns  ModalPropsType
 */
const handelCode1001 = (
    modalProps: ModalPropsType,
    hideModal: () => void 
) => {
    modalProps = {
        title: "点数不足",
        content: "当前点数不足，请前往充值Vip或点数",
        confirmText: "购买点数",
        cancelText: "订阅Vip",
        onConfirm: hideModal,
        onCancel: hideModal,
        hideModal,
    }
    return modalProps;
}
export default new MonitorCode();